<template>
  <div class="app-container">
    <PropTable
      ref="tableData"
      :loading="loading"
      :columns="column"
      :data="data"
      @reset="reset"
      @onSubmit="onSubmit"
      :unadd="false"
    >
      <template v-slot:operation="scope">
        <el-button type="primary" size="small" icon="View" @click="openPro(scope.row)">
          项目详情
        </el-button>
      </template>
    </PropTable>
  </div>
</template>

<script lang="ts" setup>
  import { onMounted, ref } from 'vue'
  import PropTable from '@/components/Table/PropTable/index.vue'
  import { postFileDetailFileList } from '@/api/controller/file-detail-controller/index'
  import { useRouter } from 'vue-router'
  const pageInfo = ref({})
  const tableData = ref([])
  const loading = ref(true)
  const column = [
    { name: 'projectBrief', label: '项目简称', inSearch: true, valueType: 'input' },
    { name: 'projectStatus', label: '项目状态', valueType: 'input' },
    { name: 'number1', label: '前期沟通文档', valueType: 'input', width: 130 },
    { name: 'number2', label: '招投标文档', valueType: 'input', width: 130 },
    { name: 'number3', label: '施工文档', valueType: 'input', width: 130 },
    { name: 'number4', label: '竣工文档', valueType: 'input', width: 130 },
    { name: 'number5', label: '合同', valueType: 'input', width: 130 },
    { name: 'number6', label: '其他', valueType: 'input', width: 130 },
    { name: 'operation', slot: true, fixed: 'right', width: 130, label: '操作', type: false },
  ]
  const data = ref(null)
  const loadData = async (val) => {
    let res = await postFileDetailFileList(val)
    data.value = res.data
  }

  const router = useRouter()
  const openPro = (row) => {
    router.push({
      name: 'projectInfo',
      state: { id: row.id },
    })
  }
  //重置搜索条件
  const reset = async () => {
    try {
      loading.value = true
      pageInfo.value = {
        pageNum: 1,
        pageSize: 15,
      }
      await loadData(pageInfo.value)
    } finally {
      loading.value = false
    }
  }
  //搜索
  const onSubmit = async (val) => {
    try {
      loading.value = true
      await loadData(val)
    } finally {
      loading.value = false
    }
  }
  //初始化
  onMounted(async () => {
    try {
      loading.value = true
      pageInfo.value = {
        pageNum: 1,
        pageSize: 15,
      }
      await loadData(pageInfo.value)
    } finally {
      loading.value = false
    }
  })
</script>

<style lang="scss" scoped>
  .app-container {
    flex: 1;
    display: flex;
    width: 100%;
    padding: 16px;
    box-sizing: border-box;
  }
</style>
